{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Minimum Number of Steps to Make Two Strings Anagram"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #hash-table #string #counting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #哈希表 #字符串 #计数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: minSteps"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #制造字母异位词的最小步骤数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你两个长度相等的字符串&nbsp;<code>s</code> 和 <code>t</code>。每一个步骤中，你可以选择将&nbsp;<code>t</code>&nbsp;中的 <strong>任一字符</strong> 替换为 <strong>另一个字符</strong>。</p>\n",
    "\n",
    "<p>返回使&nbsp;<code>t</code>&nbsp;成为&nbsp;<code>s</code>&nbsp;的字母异位词的最小步骤数。</p>\n",
    "\n",
    "<p><strong>字母异位词</strong> 指字母相同，但排列不同（也可能相同）的字符串。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输出：</strong>s = &quot;bab&quot;, t = &quot;aba&quot;\n",
    "<strong>输出：</strong>1\n",
    "<strong>提示：</strong>用 &#39;b&#39; 替换 t 中的第一个 &#39;a&#39;，t = &quot;bba&quot; 是 s 的一个字母异位词。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输出：</strong>s = &quot;leetcode&quot;, t = &quot;practice&quot;\n",
    "<strong>输出：</strong>5\n",
    "<strong>提示：</strong>用合适的字符替换 t 中的 &#39;p&#39;, &#39;r&#39;, &#39;a&#39;, &#39;i&#39; 和 &#39;c&#39;，使 t 变成 s 的字母异位词。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输出：</strong>s = &quot;anagram&quot;, t = &quot;mangaar&quot;\n",
    "<strong>输出：</strong>0\n",
    "<strong>提示：</strong>&quot;anagram&quot; 和 &quot;mangaar&quot; 本身就是一组字母异位词。 \n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 4：</strong></p>\n",
    "\n",
    "<pre><strong>输出：</strong>s = &quot;xxyyzz&quot;, t = &quot;xxyyzz&quot;\n",
    "<strong>输出：</strong>0\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 5：</strong></p>\n",
    "\n",
    "<pre><strong>输出：</strong>s = &quot;friend&quot;, t = &quot;family&quot;\n",
    "<strong>输出：</strong>4\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= s.length &lt;= 50000</code></li>\n",
    "\t<li><code>s.length == t.length</code></li>\n",
    "\t<li><code>s</code> 和 <code>t</code>&nbsp;只包含小写英文字母</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [minimum-number-of-steps-to-make-two-strings-anagram](https://leetcode.cn/problems/minimum-number-of-steps-to-make-two-strings-anagram/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [minimum-number-of-steps-to-make-two-strings-anagram](https://leetcode.cn/problems/minimum-number-of-steps-to-make-two-strings-anagram/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"bab\"\\n\"aba\"', '\"leetcode\"\\n\"practice\"', '\"anagram\"\\n\"mangaar\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        table=[0]*26\n",
    "        for ch in s:\n",
    "            table[ord(ch)-ord('a')]+=1\n",
    "        for ch in t:\n",
    "            table[ord(ch)-ord('a')]-=1\n",
    "        ans=0\n",
    "        for i in range(26):\n",
    "            ans+=abs(table[i])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        dic = {}\n",
    "        for i in s:\n",
    "            if i in dic:\n",
    "                dic[i] += 1\n",
    "            else:\n",
    "                dic[i] = 1\n",
    "        for i in t:\n",
    "            if i in dic:\n",
    "                dic[i] -= 1\n",
    "            else:\n",
    "                dic[i] = -1\n",
    "        ans = 0\n",
    "        for key in dic:\n",
    "            ans += abs(dic[key])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        from collections import Counter\n",
    "        d1,d2 = Counter(s),Counter(t)\n",
    "        res = 0\n",
    "        for k1 in d1.keys():\n",
    "            if k1 not in d2.keys():\n",
    "                res += d1[k1]\n",
    "            else:\n",
    "                res += abs(d1[k1]-d2[k1])\n",
    "        for k2 in d2.keys():\n",
    "            if k2 not in d1.keys():\n",
    "                res += d2[k2]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        dic1 = Counter(s)\n",
    "        dic2 = Counter(t)\n",
    "        a =sum((dic1-dic2).values()) \n",
    "        b =sum((dic2-dic1).values()) \n",
    "        return a+b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        temps=[0]*26\n",
    "        tempt=[0]*26\n",
    "        ans=0\n",
    "        for c in s:\n",
    "            temps[ord(c)-ord('a')]+=1\n",
    "        for c in t:\n",
    "            tempt[ord(c)-ord('a')]+=1\n",
    "        for i in range(26):\n",
    "            ans+=abs(temps[i]-tempt[i])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        ans = [0] * 26\n",
    "        for i in s:\n",
    "            ans[ord(i) - ord('a')] += 1\n",
    "        for i in t:\n",
    "            ans[ord(i) - ord('a')] -= 1 \n",
    "        res = 0\n",
    "        for i in range(len(ans)):\n",
    "            res += abs(ans[i])\n",
    "        return res    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        dic1 = Counter(s)\n",
    "        dic2 = Counter(t)\n",
    "        a =sum((dic1-dic2).values()) \n",
    "        b =sum((dic2-dic1).values()) \n",
    "        return a+b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        c1 = Counter(s)\n",
    "        c2 = Counter(t)\n",
    "        ret = 0\n",
    "        for k, v in c1.items():\n",
    "            ret += abs(v - c2[k])\n",
    "        for k, v in c2.items():\n",
    "            if k not in c1:\n",
    "                ret += c2[k]\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        res = 0\n",
    "        ls,lt = [0] * 26,[0] * 26\n",
    "        for i in s:\n",
    "            ls[ord(i)-ord('a')] += 1\n",
    "        for i in t:\n",
    "            lt[ord(i)-ord('a')] += 1\n",
    "        for a,b in zip(ls,lt):\n",
    "            res += abs(a-b)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        mp1 = Counter(s)\n",
    "        mp2 = Counter(t)\n",
    "        mp3 = (mp1 | mp2) - (mp1 & mp2)   # 并集减去交集\n",
    "        return sum(mp3.values())\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        cnt = [0] * 26\n",
    "        ans = 0\n",
    "        for x in s:\n",
    "            cnt[ord(x) - ord(\"a\")] += 1\n",
    "        for x in t:\n",
    "            cnt[ord(x) - ord(\"a\")] -= 1\n",
    "        for x in cnt:\n",
    "            ans += abs(x)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        mp1 = Counter(s)\n",
    "        mp2 = Counter(t)\n",
    "\n",
    "        mp3 = (mp1 | mp2) - (mp1 & mp2)   # 并集减去交集\n",
    "\n",
    "        return sum(mp3.values())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        cnts = Counter(s)\n",
    "        cntt = Counter(t)\n",
    "\n",
    "        ans = 0\n",
    "        for k, v in cnts.items():\n",
    "            ans += abs(v - cntt[k])\n",
    "            cntt[k] = 0\n",
    "\n",
    "        return ans + sum(cntt.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        c = Counter(s)\n",
    "        c.subtract(Counter(t))\n",
    "        return sum(map(abs, c.values()))\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        freq1 = collections.Counter(s)\n",
    "        freq2 = collections.Counter(t)\n",
    "        return sum(((freq1 | freq2) - (freq1 & freq2)).values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        rst = [0] * 26\n",
    "        base_a = ord('a')\n",
    "        total = 0\n",
    "\n",
    "        for c in s:\n",
    "            rst[ord(c) - base_a] += 1\n",
    "            total += 1\n",
    "\n",
    "        for c in t:\n",
    "            i = ord(c) - base_a\n",
    "\n",
    "            if rst[i] <= 0:\n",
    "                total += 1\n",
    "            else:\n",
    "                total -= 1\n",
    "\n",
    "            rst[i] -= 1\n",
    "\n",
    "        return total\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        cnt_s, cnt_t = Counter(s), Counter(t)\n",
    "        ans = (cnt_s | cnt_t) - (cnt_s & cnt_t)\n",
    "        return sum(ans.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        a= Counter(s)\n",
    "        b=Counter(t)\n",
    "        value=(a|b)-(a&b)\n",
    "        print(value)\n",
    "        return sum(value.values())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        dic = defaultdict(int)\n",
    "        for c in s:\n",
    "            dic[c] += 1\n",
    "        for c in t:\n",
    "            dic[c] -= 1\n",
    "        ans = 0\n",
    "        for v in list(dic.values()):\n",
    "            ans += abs(v)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        dic1 = Counter(s)\n",
    "        dic2 = Counter(t)\n",
    "        a =sum((dic1-dic2).values()) \n",
    "        b =sum((dic2-dic1).values()) \n",
    "        return a+b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        a = Counter(s)\n",
    "        b = Counter(t)\n",
    "        return sum((a - b).values()) + sum((b - a).values())\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        dicT,dicS=Counter(t),Counter(s)\n",
    "\n",
    "        ret=(dicS | dicT)-(dicS & dicT)\n",
    "        \n",
    "        return sum(ret.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        d1 = collections.defaultdict(int)\n",
    "        d2 = collections.defaultdict(int)\n",
    "        for c in s:\n",
    "            d1[c] += 1\n",
    "        for c in t:\n",
    "            d2[c] += 1\n",
    "\n",
    "        ret = 0\n",
    "        for c in d1:\n",
    "            if d1[c] > d2[c]:\n",
    "                ret += d1[c] - d2[c]\n",
    "        for c in d2:\n",
    "            if d2[c] > d1[c]:\n",
    "                ret += d2[c] - d1[c]\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        '''\n",
    "\n",
    "        '''\n",
    "        map1 = Counter(s)\n",
    "        map2 = Counter(t)\n",
    "\n",
    "        map3 = (map1 | map2) - (map1 & map2)\n",
    "\n",
    "        return sum(map3.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        nums = [0 for i in range(26)]\n",
    "        for l in s:\n",
    "            nums[ord(l) - 97] += 1\n",
    "        for l in t:\n",
    "            nums[ord(l) - 97] -= 1\n",
    "        ans = 0\n",
    "        for num in nums:\n",
    "            ans += abs(num)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        dp1 = [ 0 ] * 26\n",
    "        dp2 = [ 0 ] * 26\n",
    "        ans = 0\n",
    "        for i in range(len(s)):\n",
    "            dp1[ord(s[i])- ord('a')] += 1\n",
    "        \n",
    "        for j in range(len(t)):\n",
    "            dp2[ord(t[j])- ord('a')] += 1\n",
    "        \n",
    "        for k in range(26):\n",
    "            ans += abs(dp1[k]-dp2[k])\n",
    "        \n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        from collections import Counter\n",
    "        s_counter, t_counter = Counter(s), Counter(t)\n",
    "        return sum((s_counter - t_counter).values()) + sum((t_counter - s_counter).values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        s_map, t_map = Counter(s), Counter(t)\n",
    "        return sum(abs(s_map[key] - t_map[key])   for key in s_map.keys() | t_map.keys())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        s_dict, t_dict = {}, {}\n",
    "        for c in s:\n",
    "            s_dict[c] = 1 + s_dict.get(c, 0)\n",
    "        for c in t:\n",
    "            t_dict[c] = 1 + t_dict.get(c, 0)\n",
    "\n",
    "        diff = 0\n",
    "        for key in s_dict:\n",
    "            diff += max(s_dict[key]-t_dict.get(key, 0), 0)\n",
    "        for key in t_dict:\n",
    "            diff += max(t_dict[key]-s_dict.get(key, 0), 0)\n",
    "\n",
    "        return diff"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        ans = 0\n",
    "        cnt1, cnt2 = collections.Counter(s), collections.Counter(t)\n",
    "        for k, v in cnt1.items():\n",
    "            if k not in cnt2.keys():\n",
    "                ans += v\n",
    "            elif v > cnt2[k]:\n",
    "                diff = v - cnt2[k]\n",
    "                ans += diff\n",
    "                cnt2[k] += diff\n",
    "        \n",
    "        for k, v in cnt2.items():\n",
    "            if k not in cnt1.keys():\n",
    "                ans += v\n",
    "            elif v > cnt1[k]:\n",
    "                diff = v - cnt1[k]\n",
    "                ans += diff\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        a={}\n",
    "        b={}\n",
    "\n",
    "        for x in s:\n",
    "            a[x]=a.get(x,0)+1\n",
    "\n",
    "        for x in t:\n",
    "            b[x]=b.get(x,0)+1\n",
    "        \n",
    "        same=0\n",
    "\n",
    "        for i in range(ord('a'),ord('z')+1):\n",
    "            same+=min(a.get(chr(i),0), b.get(chr(i),0))\n",
    "\n",
    "        return len(s)+len(t)-2*same\n",
    "\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        s_count = Counter(s)\n",
    "        t_count = Counter(t)\n",
    "        print(s_count, t_count)\n",
    "\n",
    "        result = 0\n",
    "        for key, value in s_count.items():\n",
    "            if key not in t_count:\n",
    "                result += value\n",
    "            else:\n",
    "                if value != t_count[key]:\n",
    "                    result += abs(value - t_count[key])\n",
    "        \n",
    "\n",
    "        for key, value in t_count.items():\n",
    "            if key not in s_count:\n",
    "                result += value\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        rst = [0] * 26\n",
    "        bit_map = 0\n",
    "        base_a = ord('a')\n",
    "\n",
    "        for c in s:\n",
    "            rst[ord(c) - base_a] += 1\n",
    "\n",
    "        for c in t:\n",
    "            i = ord(c) - base_a\n",
    "            bit_mask = 1 << i\n",
    "\n",
    "            if rst[i] == 0:\n",
    "                bit_map |= bit_mask\n",
    "\n",
    "            if bit_map & bit_mask:\n",
    "                rst[i] += 1\n",
    "            else:\n",
    "                rst[i] -= 1\n",
    "\n",
    "        return sum(rst)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        dic1 = Counter(s)\n",
    "        dic2 = Counter(t)\n",
    "        a = dic1-dic2\n",
    "        b = dic2-dic1\n",
    "        dic3 = a+b\n",
    "        return sum(dic3.values())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        freq1 = collections.Counter(s)\n",
    "        freq2 = collections.Counter(t)\n",
    "        ans = 0\n",
    "        for key, value in freq1.items():\n",
    "            if key not in freq2:\n",
    "                ans += value\n",
    "                freq2[key] = value\n",
    "            else:\n",
    "                if value > freq2[key]:\n",
    "                    ans += (value - freq2[key])\n",
    "                    freq2[key] = value\n",
    "\n",
    "\n",
    "        for key, value in freq2.items():\n",
    "            if key not in freq1:\n",
    "                ans += value\n",
    "                freq1[key] = value\n",
    "            else:\n",
    "                if value > freq1[key]:\n",
    "                    ans += value - freq1[key]\n",
    "                    freq1[key] = value\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        c1, c2 = Counter(s), Counter(t)\n",
    "        ans = 0\n",
    "        for k in c1 | c2:\n",
    "            ans += abs(c1[k] - c2[k])\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        # 并集 - 交集\n",
    "        cnts = Counter(s)\n",
    "        cntt = Counter(t)\n",
    "        res = 0\n",
    "        for k,v in cnts.items():\n",
    "            if k not in cntt:\n",
    "                res += v\n",
    "            else:\n",
    "                if v<cntt[k]:\n",
    "                    res += (cntt[k] - v)\n",
    "        \n",
    "        for k,v in cntt.items():\n",
    "            if k not in cnts:\n",
    "                res += v\n",
    "            else:\n",
    "                if v<cnts[k]:\n",
    "                    res += (cnts[k] - v)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        sCount = Counter(s)\n",
    "        tCount = Counter(t)\n",
    "        ans = 0\n",
    "        \n",
    "        for item in sCount:\n",
    "            if item not in tCount:\n",
    "                ans += sCount[item]\n",
    "            else:\n",
    "                ans += abs(sCount[item] - tCount[item])\n",
    "        \n",
    "        for item in tCount:\n",
    "            if item not in sCount:\n",
    "                ans += tCount[item]\n",
    "        \n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    # # 哈希+计数+贪心\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        cnt1 = Counter(s)\n",
    "        cnt2 = Counter(t)\n",
    "        ans = 0\n",
    "        for i in range(26):\n",
    "            w = chr(i + ord(\"a\"))\n",
    "            ans += abs(cnt1[w] - cnt2[w])\n",
    "            \n",
    "        return ans\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        counterS=dict()\n",
    "        counterT=dict()\n",
    "        for ch in s+t:\n",
    "            counterS[ch]=0\n",
    "            counterT[ch]=0\n",
    "        for ch in s:\n",
    "            counterS[ch]+=1\n",
    "        for ch in t:\n",
    "            counterT[ch]+=1\n",
    "        ans=0\n",
    "        for key in counterS:\n",
    "            ans+=max(counterS[key],counterT[key])-min(counterS[key],counterT[key])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        cs = Counter(s)\n",
    "        ct = Counter(t)\n",
    "        ans = 0\n",
    "        for i in range(26):\n",
    "            c = chr(ord('a') + i)\n",
    "            ans += abs(cs[c] - ct[c])\n",
    "        return ans\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        s_cnt = collections.Counter(s)\n",
    "        t_cnt = collections.Counter(t)\n",
    "        ans = 0\n",
    "        for c in set(s_cnt.keys()).union(set(t_cnt.keys())):\n",
    "            if s_cnt[c] < t_cnt[c]:\n",
    "                ans += t_cnt[c] - s_cnt[c]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        return sum((Counter(t)-Counter(s)).values()) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    \n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        s_cnt = collections.Counter(s)\n",
    "        ans = 0\n",
    "        for char in t:\n",
    "            if s_cnt[char] > 0:\n",
    "                s_cnt[char] -= 1\n",
    "            else:\n",
    "                ans += 1\n",
    "\n",
    "        return ans\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        return sum((Counter(t)-Counter(s)).values()) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        return sum((Counter(s) - Counter(t)).values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "\n",
    "        sCounter = Counter(s)\n",
    "        \n",
    "        for char in t:\n",
    "            sCounter[char] -= 1\n",
    "\n",
    "        vals = list(sCounter.values())\n",
    "        posVal = sum([n for n in vals if n > 0])\n",
    "        negVal = sum([n for n in vals if n < 0])\n",
    "\n",
    "        return max(abs(posVal), abs(negVal))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        s1=set(s)\n",
    "        t1=set(t)\n",
    "        inter=s1.intersection(t1)\n",
    "        c=\"\".join(inter)\n",
    "        count=0\n",
    "        for i in c:\n",
    "            n1=0\n",
    "            n2=0\n",
    "            for j in s:\n",
    "                if i==j:\n",
    "                    n1+=1\n",
    "            for k in t:\n",
    "                if i==k:\n",
    "                    n2+=1\n",
    "            count+=min(n1,n2)\n",
    "        return len(s)-count\n",
    "\n",
    "\n",
    "    # class Solution:\n",
    "    # def minSteps(self, s: str, t: str) -> int:\n",
    "    #     sc=collections.Counter(s)\n",
    "    #     tc=collections.Counter(t)\n",
    "    #     return len(list((sc-tc).elements()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        st = collections.Counter(s)\n",
    "        res = 0\n",
    "        for c in t:\n",
    "            if st[c] > 0:\n",
    "                st[c] -= 1 # decrease difference\n",
    "            else:\n",
    "                res += 1 # chars needed\n",
    "            \n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        # 使用counter对比两者的差异\n",
    "        s_counter = Counter(s)\n",
    "        t_counter = Counter(t)\n",
    "\n",
    "        same_count = 0\n",
    "        n = len(s)\n",
    "\n",
    "        for c in s_counter:\n",
    "            if c in t_counter:\n",
    "                same_count += min(s_counter[c], t_counter[c])\n",
    "\n",
    "        return n - same_count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        # hash table for both\n",
    "        hash_s = defaultdict(int)\n",
    "        hash_t = defaultdict(int)\n",
    "        n = len(s)\n",
    "        for i in range(n):\n",
    "            hash_s[s[i]] += 1\n",
    "            hash_t[t[i]] += 1\n",
    "        \n",
    "        res = 0\n",
    "        for s_ch, s_freq in hash_s.items():\n",
    "            res += max(0, s_freq - hash_t[s_ch])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        # 求2个以ord(字母)为下标的数组，差的绝对值之和\n",
    "        s_cnt = [0] * 26\n",
    "        t_cnt = [0] * 26\n",
    "        n = len(s)\n",
    "        for i in range(n):\n",
    "            s_cnt[ord(s[i]) - ord(\"a\")] += 1\n",
    "            t_cnt[ord(t[i]) - ord(\"a\")] += 1\n",
    "        #print(s_cnt,t_cnt)\n",
    "        add = 0\n",
    "        redu = 0\n",
    "        # 正数&负数相抵消\n",
    "        for j in range(26):\n",
    "            tmp = s_cnt[j] - t_cnt[j]\n",
    "            if tmp > 0:\n",
    "                add += tmp\n",
    "            elif tmp < 0:\n",
    "                redu += tmp\n",
    "        \n",
    "        res = max(add, -redu)\n",
    "        return res\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        cts, ctt = [0] * 26, [0] * 26\n",
    "        for i in range(len(s)):\n",
    "            cts[ord(s[i]) - ord(\"a\")] += 1\n",
    "            ctt[ord(t[i]) - ord(\"a\")] += 1\n",
    "        if cts == ctt:\n",
    "            return 0\n",
    "        \n",
    "        ans = 0\n",
    "        for i in range(26):\n",
    "            ans += cts[i] - ctt[i] if cts[i] >= ctt[i] else 0\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        return (Counter(s) - Counter(t)).total()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        s1=set(s)\n",
    "        t1=set(t)\n",
    "        inter=s1.intersection(t1)\n",
    "        c=\"\".join(inter)\n",
    "        count=0\n",
    "        for i in c:\n",
    "            n1=0\n",
    "            n2=0\n",
    "            for j in s:\n",
    "                if i==j:\n",
    "                    n1+=1\n",
    "            for k in t:\n",
    "                if i==k:\n",
    "                    n2+=1\n",
    "            count+=min(n1,n2)\n",
    "        return len(s)-count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "\n",
    "        check = collections.Counter(s)\n",
    "\n",
    "        ans = 0 \n",
    "        for ch in t:\n",
    "            if check[ch]>0:\n",
    "                check[ch] -= 1\n",
    "            else:\n",
    "                ans += 1\n",
    "        return ans "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        dict_s = {}\n",
    "        dict_t = {}\n",
    "        for i in s:\n",
    "            if i in dict_s:\n",
    "                dict_s[i] += 1\n",
    "            else:\n",
    "                dict_s[i] = 1\n",
    "            #dict_s[i] = s.count(i)\n",
    "        \n",
    "        for j in t:\n",
    "            if j in dict_t:\n",
    "                dict_t[j] += 1\n",
    "            else:\n",
    "                dict_t[j] = 1\n",
    "            #dict_t[j] = t.count(j)\n",
    "            if j in dict_s and dict_s[j] != 0:\n",
    "                dict_s[j] -= 1\n",
    "        \n",
    "        for i in s:\n",
    "            if i in dict_t and dict_t[i] != 0:\n",
    "                dict_t[i] -= 1\n",
    "        \n",
    "        s_t = 0; t_s = 0\n",
    "        for v in dict_s.values():\n",
    "            s_t += v\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        for v in dict_t.values():\n",
    "            t_s += v\n",
    "        \n",
    "        return min(s_t, t_s)\n",
    "\n",
    "        \n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    # * 单次哈希计数\n",
    "    def minSteps1(self, s: str, t: str) -> int:\n",
    "        s_cnt = collections.Counter(s)\n",
    "        ans = 0\n",
    "        for char in t:\n",
    "            if s_cnt[char] > 0:\n",
    "                s_cnt[char] -= 1\n",
    "            else:\n",
    "                ans += 1\n",
    "\n",
    "        return ans\n",
    "\n",
    "\n",
    "\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        s_cnt = collections.Counter(s)\n",
    "        t_cnt = collections.Counter(t)\n",
    "        ans = 0\n",
    "        for c in set(s_cnt.keys()).union(set(t_cnt.keys())):\n",
    "            if s_cnt[c] > t_cnt[c]:\n",
    "                ans += s_cnt[c] - t_cnt[c]\n",
    "                \n",
    "        return ans\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        return sum((Counter(t)-Counter(s)).values()) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "\n",
    "        c = Counter(s)\n",
    "\n",
    "        ret = 0\n",
    "        for ch in t:\n",
    "            if ch in c:\n",
    "                c[ch] -= 1\n",
    "                if c[ch] == 0:\n",
    "                    del c[ch]\n",
    "            else:\n",
    "                ret += 1\n",
    "\n",
    "        \n",
    "        return ret\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        st = collections.Counter(s)\n",
    "        res = 0\n",
    "        for c in t:\n",
    "            if st[c] > 0:\n",
    "                st[c] -= 1 # decrease difference\n",
    "            else:\n",
    "                res += 1 # chars needed\n",
    "            \n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        counta=collections.Counter(s)\n",
    "        \n",
    "        ans=0\n",
    "        for char in t:\n",
    "            if counta[char]>0:\n",
    "                counta[char]-=1\n",
    "            else:\n",
    "                ans+=1\n",
    "        return ans\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        dic = collections.defaultdict(int) \n",
    "        for c in s:\n",
    "            dic[c] += 1\n",
    "        for c in t:\n",
    "            if dic[c]:\n",
    "                dic[c] -= 1\n",
    "        return sum(dic.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "\n",
    "        sCounter = Counter(s)\n",
    "\n",
    "        for char in t:\n",
    "            sCounter[char] -= 1\n",
    "\n",
    "        return sum(filter(lambda x: x > 0, sCounter.values()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        for c in s:\n",
    "            t=t.replace(c,'',1)\n",
    "        return len(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        tcount = {'others':0}\n",
    "        for i in t:\n",
    "            if i in tcount:\n",
    "                tcount[i]+=1\n",
    "            else:\n",
    "                tcount[i] = 1\n",
    "        for j in s:\n",
    "            if j in tcount and tcount[j]>0:\n",
    "                tcount[j]-=1\n",
    "            else:\n",
    "                tcount['others']+=1\n",
    "\n",
    "        return tcount['others']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    '''\n",
    "    Both strings have the same length.\n",
    "    Suppose s in total has x more occurrences of some letters than t, then t must have x more occurrences of some other letters.\n",
    "    To make s and t anagrams, simply replace the x additional chars in s with the x.\n",
    "    Time complexity: O(n). Space complexity: O(1). \n",
    "    '''\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        letters = 'abcdefghijklmnopqrstuvwxyz'\n",
    "        countS = {ch: 0 for ch in letters}\n",
    "        countT = {ch: 0 for ch in letters}\n",
    "        for ch in s:\n",
    "            countS[ch] += 1\n",
    "        for ch in t:\n",
    "            countT[ch] += 1\n",
    "        \n",
    "        ans = 0\n",
    "        for ch in letters:\n",
    "            if countS[ch] > countT[ch]:\n",
    "                ans += countS[ch] - countT[ch]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "\n",
    "        return sum((Counter(t)-Counter(s)).values()) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        cnts =Counter(s)\n",
    "        cntt = Counter(t)\n",
    "        ans = 0\n",
    "        for c in set(cnts.keys()).union(set(cntt.keys())):\n",
    "            if cnts[c] < cntt[c]:\n",
    "                ans += cntt[c]- cnts[c]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        return sum((Counter(s) - Counter(t)).values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        cnt_s = collections.Counter(s)\n",
    "        ans = 0\n",
    "        for ch in t:\n",
    "            if cnt_s[ch] > 0:\n",
    "                cnt_s[ch] -= 1\n",
    "            else:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        sc=collections.Counter(s)\n",
    "        tc=collections.Counter(t)\n",
    "        return sum((sc-tc).values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "\n",
    "        c = Counter(s)\n",
    "\n",
    "        ret = 0\n",
    "        for ch in t:\n",
    "            if ch in c:\n",
    "                c[ch] -= 1\n",
    "                if c[ch] == 0:\n",
    "                    del c[ch]\n",
    "            else:\n",
    "                ret += 1\n",
    "\n",
    "        \n",
    "        return ret\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "      s = Counter(s)\n",
    "      t = Counter(t)\n",
    "      cnt = 0\n",
    "      for key in set(s.keys()) | set(t.keys()):\n",
    "        cnt += abs(s[key] - t[key])\n",
    "      return cnt // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        count = [0] * 26\n",
    "\n",
    "        for char in s:\n",
    "            count[ord(char)-ord('a')] += 1\n",
    "        for char in t:\n",
    "            count[ord(char)-ord('a')] -= 1\n",
    "        \n",
    "        res = 0\n",
    "        for i in count:\n",
    "            if i > 0:\n",
    "                res += i\n",
    "\n",
    "        return res\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        cs, ct = Counter(s), Counter(t)\n",
    "        ans = 0\n",
    "        c = cs - ct\n",
    "        for v in c.values():\n",
    "            ans += abs(v)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        dt={}\n",
    "        ds={}\n",
    "        res=0\n",
    "        for i in s:\n",
    "            ds[i]=ds.get(i,0)+1\n",
    "        for i in t:\n",
    "            dt[i]=dt.get(i,0)+1\n",
    "        for k,v in ds.items():\n",
    "\n",
    "            if k not in dt:\n",
    "                res+=v\n",
    "            else:\n",
    "                if v > dt[k]:\n",
    "                    res+=v-dt[k]\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        st = collections.Counter(s)\n",
    "        res = 0\n",
    "        for c in t:\n",
    "            if st[c] > 0:\n",
    "                st[c] -= 1 # decrease difference\n",
    "            else:\n",
    "                res += 1 # chars needed\n",
    "            \n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        res = 0\n",
    "        ct = 0\n",
    "        d1, d2 = collections.Counter(s), collections.Counter(t)\n",
    "        for c in d2:\n",
    "            if d2[c] > d1[c]:\n",
    "                res += d2[c] - d1[c]\n",
    "        return res\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        count1 = Counter(s)\n",
    "        count2 = Counter(t)\n",
    "        ans = 0\n",
    "        for i in string.ascii_lowercase:\n",
    "            ans += abs(count1[i] - count2[i])\n",
    "        return ans // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        had = Counter(s)\n",
    "        ans = 0\n",
    "        for x in t:\n",
    "            if had[x] == 0:\n",
    "                ans += 1\n",
    "            else:\n",
    "                had[x] -= 1\n",
    "\n",
    "        return ans\n",
    "\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        dict_s = {}\n",
    "        dict_t = {}\n",
    "        for i in s:\n",
    "            if i in dict_s:\n",
    "                dict_s[i] += 1\n",
    "            else:\n",
    "                dict_s[i] = 1\n",
    "            #dict_s[i] = s.count(i)\n",
    "        \n",
    "        for j in t:\n",
    "            if j in dict_s and dict_s[j] != 0:\n",
    "                dict_s[j] -= 1\n",
    "        \n",
    "        s_t = 0\n",
    "        for v in dict_s.values():\n",
    "            s_t += v\n",
    "        \n",
    "        return s_t\n",
    "\n",
    "        \n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        cnt_s = Counter(s)\n",
    "        cnt_t = Counter(t)\n",
    "        ans = 0\n",
    "        for key,val in cnt_t.items():\n",
    "            if key in cnt_s.keys():\n",
    "                if cnt_s[key]>=val:\n",
    "                    cnt_s[key]-=val\n",
    "                else:\n",
    "                    cnt_s[key] = 0\n",
    "        for val in cnt_s.values():\n",
    "            ans += val\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "\n",
    "        sCounter = Counter(s)\n",
    "        \n",
    "        for char in t:\n",
    "            sCounter[char] -= 1\n",
    "\n",
    "        vals = list(sCounter.values())\n",
    "        posVal = sum([n for n in vals if n > 0])\n",
    "        negVal = sum([n for n in vals if n < 0])\n",
    "        print(sCounter)\n",
    "\n",
    "        return max(abs(posVal), abs(negVal))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        has_listA ={}\n",
    "        for i in s:\n",
    "            if i in has_listA:\n",
    "                has_listA[i] += 1\n",
    "            else:\n",
    "                has_listA[i] = 1\n",
    "        for i in t:\n",
    "            if i in has_listA:\n",
    "                has_listA[i] -= 1\n",
    "            else:\n",
    "                has_listA[i] = -1\n",
    "        s = 0\n",
    "        for i in has_listA.values():\n",
    "            s += abs(i)\n",
    "        return int(s/2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        s_map, t_map = Counter(s), Counter(t)\n",
    "        return sum(abs(s_map[key] - t_map[key]) for key in s_map.keys() | t_map.keys()) // 2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        countS = Counter(s)\n",
    "        countT = Counter(t)\n",
    "\n",
    "        same = 0\n",
    "        for key in countS.keys():\n",
    "            if key in countT:                \n",
    "                same += min(countT[key], countS[key])\n",
    "                \n",
    "        res = len(s) - same\n",
    "        return res\n",
    "        \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        cnt = [0] * 26\n",
    "        for i in range(len(s)):\n",
    "            cnt[ord(s[i]) - ord('a')] += 1\n",
    "            cnt[ord(t[i]) - ord('a')] -= 1\n",
    "        \n",
    "        res = 0\n",
    "        for i in cnt:\n",
    "            if i > 0: res += i \n",
    "        return res "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        #copy\n",
    "        \n",
    "        cnts =Counter(s)\n",
    "        cntt = Counter(t)\n",
    "        ans = 0\n",
    "        for c in set(cnts.keys()).union(set(cntt.keys())):\n",
    "            if cnts[c] < cntt[c]:\n",
    "                ans += cntt[c]- cnts[c]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        has_listA ={}\n",
    "        for i in s:\n",
    "            if i in has_listA:\n",
    "                has_listA[i] += 1\n",
    "            else:\n",
    "                has_listA[i] = 1\n",
    "        for i in t:\n",
    "            if i in has_listA:\n",
    "                has_listA[i] -= 1\n",
    "            else:\n",
    "                has_listA[i] = -1\n",
    "        s = 0\n",
    "        for i in has_listA.values():\n",
    "            s += abs(i)\n",
    "        return int(s/2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        sc = Counter(s)\n",
    "        tc = Counter(t)\n",
    "        if sc == tc:\n",
    "            return 0\n",
    "        return sum((tc - sc).values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        cnt_s=[0]*26\n",
    "        cnt_t=[0]*26\n",
    "        for i in range(len(s)):\n",
    "            cnt_s[ord(s[i])-97]+=1\n",
    "            cnt_t[ord(t[i])-97]+=1\n",
    "        ans=0\n",
    "        for i in range(26):\n",
    "            if cnt_s[i]<cnt_t[i]:\n",
    "                ans+=cnt_t[i]-cnt_s[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        res = 0\n",
    "        s_dic = collections.Counter(s)\n",
    "        t_dic = collections.Counter(t)\n",
    "        for tmp in s_dic.keys():\n",
    "            res += min(s_dic[tmp] , t_dic[tmp])   #两个字符串中相同数量的字符数\n",
    "        return len(s) - res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        ls = [0] * 26\n",
    "\n",
    "        for ss in s:\n",
    "            ls[ord(ss) - 97] += 1\n",
    "\n",
    "        for tt in t:\n",
    "            ls[ord(tt) - 97] -= 1\n",
    "\n",
    "\n",
    "        res = 0\n",
    "\n",
    "        for n in ls:\n",
    "            if n > 0:\n",
    "                res += n\n",
    "\n",
    "        return res "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        table1=[0 for _ in range(150)]\n",
    "        table2=[0 for _ in range(150)]\n",
    "        for i in range(len(s)):\n",
    "            table1[ord(s[i])]+=1\n",
    "            table2[ord(t[i])]+=1\n",
    "        dif=0\n",
    "        for i in range(len(table1)):\n",
    "            if table1[i]-table2[i]>0:\n",
    "                dif+=table1[i]-table2[i]\n",
    "        return dif"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        st = collections.Counter(s)\n",
    "        res = 0\n",
    "        for c in t:\n",
    "            if st[c] > 0:\n",
    "                st[c] -= 1 # decrease difference\n",
    "            else:\n",
    "                res += 1 # chars needed\n",
    "            \n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    # * 单次哈希计数\n",
    "    def minSteps1(self, s: str, t: str) -> int:\n",
    "        s_cnt = collections.Counter(s)\n",
    "        ans = 0\n",
    "        for char in t:\n",
    "            if s_cnt[char] > 0:\n",
    "                s_cnt[char] -= 1\n",
    "            else:\n",
    "                ans += 1\n",
    "\n",
    "        return ans\n",
    "\n",
    "\n",
    "\n",
    "    # 两次哈希计数\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        s_cnt = collections.Counter(s)\n",
    "        t_cnt = collections.Counter(t)\n",
    "        ans = 0\n",
    "        for c in (set(s_cnt.keys()) | set(t_cnt.keys())):\n",
    "            if s_cnt[c] < t_cnt[c]:\n",
    "                ans += t_cnt[c] - s_cnt[c]\n",
    "\n",
    "        return ans\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        a_count = Counter(list(s))\n",
    "        b_count = Counter(list(t))\n",
    "        result = 0\n",
    "        for key, value in a_count.items():\n",
    "            if key in b_count:\n",
    "                if b_count[key] < value:\n",
    "                    result += (value - b_count[key])\n",
    "            else:\n",
    "                result += value\n",
    "        return result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        has_listA ={}\n",
    "        for i in s:\n",
    "            if i in has_listA:\n",
    "                has_listA[i] += 1\n",
    "            else:\n",
    "                has_listA[i] = 1\n",
    "        for i in t:\n",
    "            if i in has_listA:\n",
    "                has_listA[i] -= 1\n",
    "            else:\n",
    "                has_listA[i] = -1\n",
    "        s = 0\n",
    "        for i in has_listA.values():\n",
    "            s += abs(i/2)\n",
    "        return int(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        zd = dict()\n",
    "        for i in s:\n",
    "            zd[i] = zd.get(i, 0) + 1\n",
    "        for i in t:\n",
    "            if i in zd and zd[i] > 0:\n",
    "                zd[i] -= 1\n",
    "        return sum(zd.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        res = 0\n",
    "        ct = 0\n",
    "        d1, d2 = collections.Counter(s), collections.Counter(t)\n",
    "        for c in d2:\n",
    "            if d2[c] > d1[c]:\n",
    "                res += d2[c] - d1[c]\n",
    "        return res\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        c1 = Counter(s)\n",
    "        c2 = Counter(t)\n",
    "\n",
    "        res = 0\n",
    "        for k in c1.keys():\n",
    "            if c2[k] < c1[k]:\n",
    "                res += c1[k] - c2[k]\n",
    "\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        c1 = Counter(s)\n",
    "        c2 = Counter(t)\n",
    "\n",
    "        res = 0\n",
    "        for k in c1.keys():\n",
    "            tmp = c1[k] - c2[k]\n",
    "            if tmp > 0:\n",
    "                res += tmp\n",
    "\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        cnt1 = Counter(s)\n",
    "        cnt2 = Counter(t)\n",
    "        ans = 0\n",
    "        for w in cnt2:\n",
    "            ans += min(cnt1[w], cnt2[w])\n",
    "        return len(t) - ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from bisect import bisect_left, bisect_right, insort_left, insort_right, insort, bisect\n",
    "from math import ceil, floor, pow, gcd, sqrt, log10, fabs, fmod, factorial, inf, pi, e\n",
    "from heapq import heapify, heapreplace, heappush, heappop, heappushpop, nlargest, nsmallest\n",
    "from collections import defaultdict, Counter, deque\n",
    "from itertools import permutations, combinations, combinations_with_replacement, accumulate, count, groupby\n",
    "from queue import PriorityQueue, Queue, LifoQueue\n",
    "from functools import lru_cache\n",
    "from typing import List, Optional\n",
    "import sys\n",
    "\n",
    "sys.setrecursionlimit(10001000)\n",
    "\n",
    "MOD = int(1e9 + 7)\n",
    "INF = int(1e20)\n",
    "INFMIN = float('-inf')\n",
    "INFMAX = float('inf')\n",
    "PI = 3.141592653589793\n",
    "direc = [(1, 0), (0, 1), (-1, 0), (0, -1)]\n",
    "direc8 = [(1, 0), (0, 1), (-1, 0), (0, -1), (1, 1), (1, -1), (-1, 1), (-1, -1)]\n",
    "ALPS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'\n",
    "alps = 'abcdefghijklmnopqrstuvwxyz'\n",
    "\n",
    "\n",
    "def alp(i):\n",
    "    return chr(ord('a') + i % 26)  # i=0->'a', i=25->'z'\n",
    "\n",
    "\n",
    "def input():\n",
    "    return sys.stdin.readline().rstrip()\n",
    "\n",
    "\n",
    "def end(r=-1):\n",
    "    print(r)\n",
    "    exit()\n",
    "\n",
    "\n",
    "# -*- coding: utf-8 -*-\n",
    "# @Author  : hakusai\n",
    "# @Time    : 2023/09/09 14:23\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        s_cnt = Counter(s)\n",
    "        ans = 0\n",
    "        for c in t:\n",
    "            if s_cnt[c] > 0:\n",
    "                s_cnt[c] -= 1\n",
    "            else:\n",
    "                ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        ans = 0\n",
    "        cnt = [0] * 26\n",
    "        for c in s:\n",
    "            print(ord(c))\n",
    "            cnt[ord(c) - ord('a')] += 1\n",
    "        for c in t:\n",
    "            index = ord(c) - ord('a')\n",
    "            if (cnt[index] == 0):\n",
    "                 ans += 1\n",
    "            else :\n",
    "                cnt[index] -= 1\n",
    "\n",
    "        return ans;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minSteps(self, s: str, t: str) -> int:\n",
    "        s = sorted(s)\n",
    "        count_s = {}\n",
    "        count_t = {}\n",
    "        step = 0\n",
    "        for i in s:\n",
    "            if i not in count_s:\n",
    "                count_s[i] = 1\n",
    "            else:\n",
    "                count_s[i] += 1\n",
    "\n",
    "        for i in t:\n",
    "            if i not in count_t:\n",
    "                count_t[i] = 1\n",
    "            else:\n",
    "                count_t[i] += 1\n",
    "\n",
    "        for k,v in count_s.items():\n",
    "            if k not in count_t:\n",
    "                step += v\n",
    "            else:\n",
    "                if v > count_t[k]:\n",
    "                    step += v - count_t[k]\n",
    "        return step\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
